﻿using Newtonsoft.Json;

namespace DB2WORD.Logics
{
    /// <summary>
    /// JSON辅助操作类
    /// </summary>
    public static class JsonHelper
    {
        public static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings()
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
            Formatting = Formatting.Indented,
            DateFormatString = "yyyy-MM-dd HH:mm:ss",
        };

        public static T Clone<T>(T t)
        {
            if(t == null)
            {
                return t;
            }
            var json = JsonConvert.SerializeObject(t, JsonSerializerSettings);
            var obj = JsonConvert.DeserializeObject<T>(json);
            return obj;
        }
    }
}
